import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

public class GeneString {
	int start;
	ArrayList seq;
	
	public GeneString(ArrayList rect) {
		seq = new ArrayList(rect.size());
	}
	
	public GeneString newRandom(ArrayList rect){
		boolean takenByA[] = new boolean[rect.size()];
		boolean takenByB[] = new boolean[rect.size()];
		GeneString string = new GeneString(rect);
		for(int i = 0; i < rect.size(); i++){
			int gene = (int)Math.floor(Math.random() * rect.size());
			int a = getUntaken(takenByA, gene);
			takenByA[gene] = true;
			gene = (int)Math.floor(Math.random() * rect.size());
			int b = getUntaken(takenByB, gene);
			takenByA[gene] = true;
			string.seq.add(new Pair(a, b, (RectNode)rect.get(i)));
		}
		string.start = (int)Math.floor(Math.random() * rect.size());
		return string;
	}
	
	public Pair getPair(int i){
		return (Pair)seq.get(i);
	}
	
	private int getUntaken(boolean[] taken, int i){
		int closest = 999999;
		for(int u = 0; u < taken.length; u++){
			if(Math.abs(u - i) < closest && !taken[u])
				closest = u;
		}
		return closest;
	}


	


}
